package main

import (
	"log"

	"go-micro.dev/v4"

	dbCli "pan/service/dbproxy/client"
	"pan/service/download/config"
	downloadProto "pan/service/download/proto"
	"pan/service/download/route"
	downlaodRpc "pan/service/download/rpc"
)

func startRPCService() {
	service := micro.NewService(
		micro.Name("download"), // 在注册中心中的服务名称
	)
	service.Init()

	// 初始化dbproxy client
	dbCli.Init(service)

	downloadProto.RegisterDownloadServiceHandler(service.Server(), new(downlaodRpc.Download))
	if err := service.Run(); err != nil {
		log.Println(err)
	}
}

func startAPIService() {
	router := route.Router()
	router.Run(config.DownloadServiceHost)
}

func main() {
	// api 服务
	go startAPIService()

	// rpc 服务
	startRPCService()
}
